package com.interview.case01;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Main {
    public static void main(String[] args) {
        // 创建购物车
        ShoppingCart cartA = new ShoppingCart();

        // 顾客A购买的水果斤数
        int applesA = 5;        // 5斤苹果
        int strawberriesA = 3;  // 3斤草莓

        // 将水果添加到购物车
        Fruit apple = new Apple();
        Fruit strawberry = new Strawberry();
        cartA.addFruit(apple, applesA);
        cartA.addFruit(strawberry, strawberriesA);

        // 计算总价
        BigDecimal totalA = cartA.calculateTotalPrice();

        // 预期总价：5 * 8.00 + 3 * 13.00 = 40.00 + 39.00 = 79.00元
        BigDecimal expectedA = new BigDecimal("5").multiply(new BigDecimal("8.00"))
                .add(new BigDecimal("3").multiply(new BigDecimal("13.00")));

        // 设置小数点精度
        totalA = totalA.setScale(2, RoundingMode.HALF_UP);
        expectedA = expectedA.setScale(2, RoundingMode.HALF_UP);

        // 输出结果
        System.out.println("顾客A购买的总价: " + totalA + " 元");

        // 验证计算结果
        if (totalA.compareTo(expectedA) == 0) {
            System.out.println("测试通过！");
        } else {
            System.out.println("测试失败！预期: " + expectedA + " 元, 实际: " + totalA + " 元");
        }
    }
}
